﻿using System.Collections.Generic;
//
using PerceptiveMCAPI;
//

namespace PerceptiveMCAPI_Test
{
   public partial class get_listWebhooks : System.Web.UI.UserControl
   {
      public ApiMethod method { get; set; }

      public string listId
      {
         get { return tbListId.Text.Trim(); }
         set { tbListId.Text = value; }
      }
      public string url
      {
         get { return tbUrl.Text.Trim(); }
         private set { tbUrl.Text = value; }
      }
      public Dictionary<EnumValues.listWebhookActions, bool> actions
      {
         get { return getActions(); }
         private set { setActions(); }
      }
      public Dictionary<EnumValues.listWebhookSources, bool> sources
      {
         get { return getSources(); }
         private set { setSources(); }
      }

      //-------------------------------------
      public bool Setup()
      {
         this.Visible = true;
         lblSection.Text = method.section;
         lblMethod.Text = method.name;
         //
         switch ( method.name )
         {
            case "listWebhooks":
               divUrl.Visible = false;
               divOptions.Visible = false;
               break;
            case "listWebhookAdd":
               divUrl.Visible = true;
               divOptions.Visible = true;
               setActions();
               setSources();
               break;
            case "listWebhookDel":
               divUrl.Visible = true;
               divOptions.Visible = false;
               break;
         }
         //
         return true;
      }

      private Dictionary<EnumValues.listWebhookActions, bool> getActions()
      {
         Dictionary<EnumValues.listWebhookActions, bool> actions =
            new Dictionary<EnumValues.listWebhookActions, bool>();
         actions.Add( EnumValues.listWebhookActions.subscribe, cbSubscribe.Checked );
         actions.Add( EnumValues.listWebhookActions.unsubscribe, cbUnsubscribe.Checked );
         actions.Add( EnumValues.listWebhookActions.profile, cbProfile.Checked );
         actions.Add( EnumValues.listWebhookActions.cleaned, cbCleaned.Checked );
         actions.Add( EnumValues.listWebhookActions.upemail, cbUpEmail.Checked );
         //
         return actions;
      }
      private Dictionary<EnumValues.listWebhookSources, bool> getSources()
      {
         Dictionary<EnumValues.listWebhookSources, bool> sources =
            new Dictionary<EnumValues.listWebhookSources, bool>();
         //
         sources.Add( EnumValues.listWebhookSources.user, cbUser.Checked );
         sources.Add( EnumValues.listWebhookSources.admin, cbAdmin.Checked );
         sources.Add( EnumValues.listWebhookSources.api, cbApi.Checked );
         //
         return sources;
      }
      // -----------------------
      private void setActions()
      {
         // default actions
         cbSubscribe.Checked = MCAPISettings.default_listWebhook_actions_subscribe;
         cbUnsubscribe.Checked = MCAPISettings.default_listWebhook_actions_unsubscribe;
         cbProfile.Checked = MCAPISettings.default_listWebhook_actions_profile;
         cbCleaned.Checked = MCAPISettings.default_listWebhook_actions_cleaned;
         cbUpEmail.Checked = MCAPISettings.default_listWebhook_actions_upemail;
      }
      private void setSources()
      {
         // default sources
         cbAdmin.Checked = MCAPISettings.default_listWebhook_sources_admin;
         cbUser.Checked = MCAPISettings.default_listWebhook_sources_user;
         cbApi.Checked = MCAPISettings.default_listWebhook_sources_api;
      }
   }
}